<template>

	<view>
		<u-button @click="startRecord">开始录音</u-button>
		<u-button @click="endRecord">停止录音</u-button>
		<u-button @click="playVoice">播放录音</u-button>
		<u-button @click="chImage">选择图片</u-button>
	</view>
	<view>
		<image v-for="(item,index) in imageList" :key="index" :src="item"></image>
	</view>
</template>

<script>
	const recorderManager = uni.getRecorderManager();
	const innerAudioContext = uni.createInnerAudioContext();

	innerAudioContext.autoplay = true;

	export default {
		data() {
			return {
				text: 'uni-app',
				voicePath: '',
				imageList: [],
				params: {
					phone: '',
					nickName: ''
				}
			}
		},
		onLoad() {
			let self = this;
			recorderManager.onStop(function(res) {
				console.log('recorder stop' + JSON.stringify(res));
				self.voicePath = res.tempFilePath;
			});
			this.getInfo();

		},
		methods: {

			startRecord: function() {
				console.log('开始录音');

				recorderManager.start();
			},
			endRecord: function() {
				console.log('录音结束');
				recorderManager.stop();
			},
			playVoice: function() {
				console.log('播放录音');

				if (this.voicePath) {
					innerAudioContext.src = this.voicePath;
					innerAudioContext.play();
				}
			},
			chImage: function() {
				let _self = this;
				uni.chooseImage({
					count: 6, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					success: function(res) {
						console.log(JSON.stringify(res.tempFilePaths));
						_self.imageList = res.tempFilePaths;
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #ededed;
	}

	.camera {
		width: 54px;
		height: 44px;

		&:active {
			background-color: #ededed;
		}
	}

	.user-box {
		background-color: #fff;
	}
</style>
